<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页</title>
    <style>
        html,
        body {
            height: 100%;
        }

        body {
            background-image: url(./img/login-background.jpg);
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .box {
            box-sizing: border-box;
            min-width: 400px;
            background-color: white;
            border-radius: 10px;
            overflow: hidden;
        }

        .box h2 {
            text-align: center;
            line-height: 60px;
            color: gray;
        }

        .box .content {
            margin: 30px;
        }

        .box .content .one {
            display: flex;
            justify-content: space-between;
            margin-bottom: 20px;
        }

        .box .content .one input {
            width: 100%;
            box-sizing: border-box;
            height: 40px;
            border-radius: 5px;
            border: 1px solid #ccc;
            padding-left: 15px;
            outline: none;
        }

        .box .content .one a {
            text-decoration: none;
            color: #555;
            padding-left: 220px;
        }

        .box .form .one{
            display: flex;
            justify-content: center;
        }

        .box .content .one button {
            width: 100%;
            border: none;
            background-color: lightgreen;
            color: white;
            padding: 10px 20px;
            border-radius: 5px;
        }
    </style>
</head>

<body>
    <div class="box">

        <h2>后台管理系统</h2>
        <div class="content">
            <div class="one">
                <input type="text" placeholder="账号">
            </div>
            <div class="one">
                <input type="password" placeholder="密码">
            </div>
            <div class="one">
                <input type="password" placeholder="确认密码">
            </div>
            <div class="one ">
                <button>注册</button>
            </div>
            <div class="one">
                <a href="./login.html">使用已有账户登录</a>
            </div>
        </div>
    </div>
</body>

</html>
<script src="./axios.min.js"></script>
<script>
    //获取输入框
    var inp = document.querySelectorAll('input');

    //获取注册按钮
    var registerBtn = document.querySelector('button');

    //绑定点击事件
    registerBtn.onclick = function () {
        if (inp[0].value &&
            inp[1].value &&
            inp[2].value 
        ) {
            if (/^1[3-9]\d{9}$/.test(inp[0].value) &&
                inp[1].value == inp[2].value
            ) {
                axios.post('/user/register', {
                    phone: inp[0].value,
                    pass: inp[1].value,
                }).then((res) => {
                    console.log(res.data);
                })
            } else if (/^1[3-9]\d{9}$/.test(inp[0].value) == false) {
                alert('手机号格式不正确!');
            } else {
                alert('两次密码不一致!');
            }
        } else {
            alert('注册信息不完整!');
        }
    }
</script>